package org.sft.config.web;

import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

/**
 * @author sft
 *
 *         2016年5月30日
 */
@Configuration
public class FastJSONMessageConfig extends WebMvcConfigurerAdapter{

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#configureMessageConverters(java.util.List)
	 */
	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		converters.clear();
		FastJsonConfig fasConfig=new FastJsonConfig();
		fasConfig.setDateFormat("yyyy-MM-dd");
		//List<SerializerFeature> features=new ArrayList<>();
		SerializerFeature[] features={SerializerFeature.WriteMapNullValue,SerializerFeature.WriteDateUseDateFormat,SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteNullNumberAsZero};
		fasConfig.setSerializerFeatures(features);
		FastJsonHttpMessageConverter fsConverter=new FastJsonHttpMessageConverter();
		fsConverter.setFastJsonConfig(fasConfig);
		converters.add(fsConverter);
		super.configureMessageConverters(converters);
	}

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#extendMessageConverters(java.util.List)
	 */
	@Override
	public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
		// TODO Auto-generated method stub
		super.extendMessageConverters(converters);
	}
	
	
}
